package com.ruihu.admin.common.constant;

import com.ruihu.admin.common.domain.BaseEnum;

import java.util.Arrays;
import java.util.Optional;

public enum SaveResultEnum implements BaseEnum {
    EXISTS(0, "已经存在"),

    ADD_SUCCESS(1, "新增成功"),

    UPDATE_SUCCESS(2, "更新成功");

    private Integer value;
    private String desc;

    SaveResultEnum(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    @Override
    public Integer getValue() {
        return value;
    }
    @Override
    public String getDesc() {
        return desc;
    }

    public static SaveResultEnum valueOf(Integer status) {
        SaveResultEnum[] values = SaveResultEnum.values();
        Optional<SaveResultEnum> first = Arrays.stream(values).filter(e -> e.getValue().equals(status)).findFirst();
        return !first.isPresent() ? null : first.get();
    }

    public static boolean isExist(Integer status) {
        SaveResultEnum saveResultEnum = valueOf(status);
        return saveResultEnum != null;
    }
}
